<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once(ROOT_PATH."class/user.class.php");

$user = new user;
$user->status=STATUS_ACTIVE;
$user->teamid=$CURRENT_USER->teamid;
$ulist = $loader->loadListBy($user,$user->listByFilters());

$userstats=array();

$sql = "SELECT count(id) as count FROM ".FILES.PROJECT_PREFIX.$prjid." WHERE teamid=".util::str($CURRENT_USER->teamid);
$totalfiles = $loader->fetchcount($sql);

foreach ($ulist as $u) {
	$sql = "SELECT statusid, count(distinct(fileid)) as count FROM ".HISTORY.PROJECT_PREFIX.$prjid." WHERE userid = ".util::str($u->userid)." and (statusid=".util::str(FILE_STATUS_LOCKED)." or statusid=".util::str(FILE_STATUS_PROOF).") GROUP BY statusid";	
	$list = $loader->fetchlist($sql);
	$temp = array();
	$temp['userid'] = $u->userid;
	foreach ($FILE_STATUS_LIST as $fs) {
		$temp[trim($fs)] = 0;
	}
	foreach ($list as $c) {
		$temp[$c['statusid']] = $c['count'];
	}
	array_push($userstats,$temp);
}

$tm->assign('totalfiles',$totalfiles);
$tm->assign('userstats',$userstats);		
$content = $tm->fetch('userstats.tpl');	

?>